window.Util = {

    //获取区间随机值
    randomNum(Min, Max) {
        if (Max < Min) {
            Max = Min;
        }
        return Math.floor(Math.random() * (Max - Min + 1) + Min);

        var Range = Max - Min;
        var Rand = Math.random();
        var num = Min + Math.floor(Rand * Range);
        return num;
    },

    //获取区间随机值
    random(Min, Max) {
        if (Max < Min) {
            Max = Min;
        }
        return Math.random() * (Max - Min + 1) + Min;
    },


    remove(arr, b) {
        let a = arr.indexOf(b);
        if (a >= 0) {
            arr.splice(a, 1);
            return true;
        }
        return false;
    },

    play(url, loop, volume) {

        if (loop == null) {
            loop = false;
        }
        if (volume == null) {
            volume = 1;
        }

        cc.loader.loadRes(url, cc.AudioClip, (err, data) => {
            if (err) {
                cc.error(err);
                return;
            }
            cc.audioEngine.play(data, loop, volume);
        });
    },



    remove(arr, b) {
        var a = arr.indexOf(b);
        if (a >= 0) {
            arr.splice(a, 1);
            return true;
        }
        return false;
    },

    money(hp) {//一、十、百、千、万、亿、兆、京、垓、秭、壤、沟、涧、正、载
        let num = hp;
        if (hp >= 100000000000000000000000000000000) {
            num = Math.floor(hp / 100000000000000000000000000000000 * 10) / 10 + "万秭";
        } else if (hp >= 10000000000000000000000000000000) {
            num = Math.floor(hp / 10000000000000000000000000000000 * 10) / 10 + "千秭";
        }
        // else if (hp >= 1000000000000000000000000000000) {
        //     num = Math.floor(hp / 1000000000000000000000000000000 * 10) / 10 + "百秭";
        // } else if (hp >= 100000000000000000000000000000) {
        //     num = Math.floor(hp / 100000000000000000000000000000 * 10) / 10 + "十秭";
        // } 
        else if (hp >= 10000000000000000000000000000) {
            num = Math.floor(hp / 10000000000000000000000000000 * 10) / 10 + "秭";
        }
        else if (hp >= 1000000000000000000000000000) {
            num = Math.floor(hp / 1000000000000000000000000000 * 10) / 10 + "万垓";
        } else if (hp >= 100000000000000000000000000) {
            num = Math.floor(hp / 100000000000000000000000000 * 10) / 10 + "千垓";
        }
        // else if (hp >= 10000000000000000000000000) {
        //     num = Math.floor(hp / 10000000000000000000000000 * 10) / 10 + "百垓";
        // } else if (hp >= 1000000000000000000000000) {
        //     num = Math.floor(hp / 1000000000000000000000000 * 10) / 10 + "十垓";
        // } 
        else if (hp >= 100000000000000000000000) {
            num = Math.floor(hp / 100000000000000000000000 * 10) / 10 + "垓";
        }

        else if (hp >= 10000000000000000000000) {
            num = Math.floor(hp / 10000000000000000000000 * 10) / 10 + "万京";
        } else if (hp >= 1000000000000000000000) {
            num = Math.floor(hp / 1000000000000000000000 * 10) / 10 + "千京";
        }
        // else if (hp >= 100000000000000000000) {
        //     num = Math.floor(hp / 100000000000000000000 * 10) / 10 + "百京";
        // } else if (hp >= 10000000000000000000) {
        //     num = Math.floor(hp / 10000000000000000000 * 10) / 10 + "十京";
        // } 
        else if (hp >= 1000000000000000000) {
            num = Math.floor(hp / 1000000000000000000 * 10) / 10 + "京";
        } else if (hp >= 100000000000000000) {
            num = Math.floor(hp / 100000000000000000 * 10) / 10 + "万兆";
        } else if (hp >= 10000000000000000) {
            num = Math.floor(hp / 10000000000000000 * 10) / 10 + "千兆";
        }
        // else if (hp >= 1000000000000000) {
        //     num = Math.floor(hp / 1000000000000000 * 10) / 10 + "百兆";
        // } else if (hp >= 100000000000000) {
        //     num = Math.floor(hp / 100000000000000 * 10) / 10 + "十兆";
        // } 

        else if (hp >= 10000000000000) {
            num = Math.floor(hp / 10000000000000 * 10) / 10 + "兆";
        } else if (hp >= 1000000000000) {
            num = Math.floor(hp / 1000000000000 * 10) / 10 + "万亿";
        } else if (hp >= 100000000000) {
            num = Math.floor(hp / 100000000000 * 10) / 10 + "千亿";
        }
        // else if (hp > 10000000000) {
        //     num = Math.floor(hp / 10000000000 * 10) / 10 + "百亿";
        // } 
        // else if (hp > 1000000000) {
        //     num = Math.floor(hp / 1000000000 * 10) / 10 + "十亿";
        // } 
        else if (hp >= 100000000) {
            num = Math.floor(hp / 100000000 * 10) / 10 + "亿";
        } else if (hp >= 10000000) {
            num = Math.floor(hp / 10000000 * 10) / 10 + "千万";
        }
        //  else if (hp > 1000000) {
        //     num = Math.floor(hp / 1000000 * 10) / 10 + "百万";
        // } 
        // else if (hp > 100000) {
        //     num = Math.floor(hp / 100000 * 10) / 10 + "十万";
        // } 
        else if (hp >= 10000) {
            num = Math.floor(hp / 10000 * 10) / 10 + "万";
        } else if (hp >= 1000) {
            num = Math.floor(hp / 1000 * 10) / 10 + "千";
        }
        return num;
    },
};
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}